import java.util.ArrayList;
import java.util.Scanner;

public class Hotel {

    ArrayList<Room> roomList = new ArrayList<Room>();

    ArrayList<Order> orderList = new ArrayList<Order>();

    Scanner scanner = new Scanner(System.in);

    private int orderNum = 0;


    public Hotel() {
        roomList.add(new Room("A", "单人间", false));
        roomList.add(new Room("B", "单人间", false));
        roomList.add(new Room("B", "单人间", false));
        roomList.add(new Room("C", "双人间", true));
        roomList.add(new Room("D", "单人间", false));
        roomList.add(new Room("E", "单人间", false));
        roomList.add(new Room("F", "双人间", true));
        roomList.add(new Room("G", "双人间", false));
        roomList.add(new Room("H", "单人间", false));
    }

    public void login(String userName, String password) {
        String correctUserName = "admin";
        String correctPassword = "123456";
        if (userName.equals(correctUserName) && password.equals(correctPassword)) {
            System.out.println("欢迎使用酒店管理系统！");
            System.out.println("1.查询所有房间信息");
            System.out.println("2.预订房间");
            System.out.println("3.退订房间");
            System.out.println("4.查看已预订房间");
            System.out.println("5.查看订单信息");
            System.out.println("6.退出系统");
        } else {
            System.out.println("账号密码错误：请重新输入");
        }
    }

    public void choose() {
        Boolean flag = true;
        while (flag) {
            System.out.print("请输入要执行的操作：");
            int operatorNum = scanner.nextInt();
            switch (operatorNum) {
                case 1:
                    //查询所有房间信息
                    findAllRoom();
                    break;
                case 2:
                    //预订房间
                    bookRoom();
                    break;
                case 3:
                    //退订房间
                    countermandRoom();
                    break;
                case 4:
                    //查看已预订房间
                    findReservedRoom();
                    break;
                case 5:
                    //查看订单
                    findOrder();
                    break;
                default:
                    //退出系统
                    flag = false;
            }
        }
        System.out.println("感谢使用酒店管理系统，再见！");
    }

    private void findReservedRoom() {
        System.out.println("已预订房间信息如下：");
        for (Room room : roomList) {
            if (room.getReserved().equals(true)) {
                System.out.println(room);
            }
        }
    }

    private void countermandRoom() {
        System.out.print("请输入要退订的订单号：");
        int orderNum = scanner.nextInt();
        if (orderList.size() < 1) {
            System.out.println("未找到对应的预订记录，请检查订单号是否正确！");
        }
        for (Order order : orderList) {
            if (order.getOrderNum() == orderNum) {
                System.out.println("退订成功");
                Room room = order.getRoom();
                String roomNumber = room.getRoomNumber();
                for (Room room1 : roomList) {
                    if (room1.getRoomNumber().equals(roomNumber)) {
                        room1.setReserved(false);
                    }
                }
                break;
            }
            System.out.println("未找到对应的预订记录，请检查订单号是否正确！");
        }
    }

    private void findOrder() {
        for (Order order : orderList) {
            System.out.println(order);
        }
    }

    private void bookRoom() {
        System.out.print("请输入要预订的房型（单人间/双人间）：");
        String roomType = scanner.next();
        System.out.print("请输入入住日期：");
        String date = scanner.next();
        orderNum++;
        for (Room room : roomList) {
            if (room.getRoomType().equals(roomType) && room.getReserved().equals(false)) {
                room.setReserved(true);
                System.out.println("预订成功！订单号为：" + orderNum + "，入住日期为：" + date + "房间信息为：" + room);
                Order order = new Order();
                order.setOrderNum(orderNum);
                order.setDate(date);
                order.setRoom(room);
                orderList.add(order);
                break;
            }
        }

    }

    private void findAllRoom() {
        for (Room room : roomList) {
            System.out.println(room);
        }
    }
}
